package main

import (
	"context"
	"fmt"
	"greeter/proto/greeterServer"
	"net"

	"google.golang.org/grpc"
)

type Hello struct {
}

func (this Hello) SayHello(c context.Context, req *greeterServer.HelloReq) (*greeterServer.HelloRes, error) {
	fmt.Println(req)
	return &greeterServer.HelloRes{
		Message: "你好" + req.GetName(),
		Success: true,
	}, nil
}

func main() {
	// 1.初始化grpc
	grpcServer := grpc.NewServer()

	// 2.注册服务
	greeterServer.RegisterGreeterServer(grpcServer, &Hello{})

	// 3.监听端口
	listener, err := net.Listen("tcp", "127.0.0.1:9002")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("端口监听9002")
	// 4.启动服务
	grpcServer.Serve(listener)

}
